package IO特殊操作流;

import java.io.*;
/*
* 一个对象想要被序列化，该对象所属的类必须实现Serializable接口
* serializable是一个标记接口，实现该接口，不需要重写任何方法
* */
public class 对象序列化流 {
    public static void main(String[] args) throws IOException {
        /*ObjectOutputStream(OutputStream out) 创建一个写入指定的OutputStream的ObjectOutputStream*/
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("day10\\oos.txt"));
        /*创建对象*/
        Student1 s = new Student1("林青霞", 30);
        /*void writeObject(Object obj) 将指定的对象写入ObjectOutputStream*/
        oos.writeObject(s);
        /*释放资源*/
        oos.close();
    }
}
/*
* 学生类
* */
class Student1 implements Serializable{
    private String name;
    private int age;
    public Student1(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public Student1() {
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    @Override
    public String toString() {
        return "Student1{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}